package com.aspyn.tabtest;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.View.OnTouchListener;
import android.view.View;

public class DrawView extends View implements OnTouchListener {

	private Ball ball1;
	private Paint paint;
	
	public DrawView(Context context) {
		super(context);
		setFocusable(true);
		
		ball1 = new Ball(60, 60, 5, 5, 25, Color.BLUE, 0, context, R.drawable.ballicon);
		
		setFocusableInTouchMode(true);
		
		this.setOnTouchListener(this);
		
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public void onDraw(Canvas c) {
		int x = ball1.getX(), y = ball1.getY(), r = ball1.getRadius();
		
		if (x+r >= 480 || x-r <= 0) {
			ball1.setXVel(-ball1.getXVel());
		}
		if (y+r >= 720 || y-r <= 0) {
			ball1.setYVel(-ball1.getYVel());
		}
		
		ball1.move(ball1.getX()+ball1.getXVel(), ball1.getY()+ball1.getYVel(), ball1);
		paint = new Paint();
		paint.setColor(Color.BLUE);
		paint.setAntiAlias(true);
		
		c.drawBitmap(ball1.getImage(), ball1.getX(),ball1.getY(), null);
		
//		c.drawCircle(ball1.getX(), ball1.getY(), ball1.getRadius(), paint);//Ball class manages the circle (its coordinates, color, velocity, etc.)
		invalidate();
	}

	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		ball1.setX((int)event.getX());
		ball1.setY((int)event.getY());
		return true;
	}
}
